<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    const TYPE_SINGLE = 'single';
    const TYPE_BOX    = 'box';

    public static $typeMap = [
        self::TYPE_SINGLE => '单个',
        self::TYPE_BOX    => '礼盒',
    ];

    public function getImageAttribute($value)
    {
        return getImageDomain($value);
    }

    public function getBarcodeImageAttribute($value)
    {
        return getImageDomain($value);
    }

    // 对应商品分类
    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function productTags()
    {
        return $this->belongsToMany(Tag::class, 'product_tags', 'product_id', 'tag_id');
    }
}
